﻿using Linker.TaskCenter.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.BackgroundWorkers.Quartz;
using Volo.Abp.Domain;
using Volo.Abp.Modularity;
using Volo.Abp.Threading;

namespace Linker.TaskCenter
{
    [DependsOn(
        typeof(AbpDddDomainModule),
        typeof(TaskCenterDomainSharedModule),
        typeof(AbpThreadingModule),
        typeof(AbpBackgroundWorkersQuartzModule)
    )]
    public class TaskCenterDomainModule : AbpModule
    {
        public override void OnApplicationInitialization(ApplicationInitializationContext context)
        {
            base.OnApplicationInitialization(context);
            AsyncHelper.RunSync(() => context.ServiceProvider.GetRequiredService<TaskWorker>().StartAsync());
        }


        public override void OnApplicationShutdown(ApplicationShutdownContext context)
        {
            base.OnApplicationShutdown(context);
            AsyncHelper.RunSync(() => context.ServiceProvider.GetRequiredService<TaskWorker>().StopAsync());
        }
    }
}